<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="stylesheet" href="../../static/css/font.css" th:href="@{/css/font.css}">
    <link rel="stylesheet" href="../../static/css/xadmin.css" th:href="@{/css/xadmin.css}">
    <link rel="stylesheet" href="../../static/css/all-member.css" th:href="@{/css/all-member.css}">
</head>

<body>
    <div style="overflow-y:scroll;" id="form-container">
        <form action="" class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">批次名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="batchName" autocomplete="off" required lay-verify="required"
                        class="layui-input">
                </div>
                <label class="layui-form-label">开始时间:</label>
                <div class="layui-input-block">
                    <input name="startTime" id="startTime" type="text" autocomplete="off" required lay-verify="required"
                        class="layui-input">
                </div>
                <label class="layui-form-label">结束时间:</label>
                <div class="layui-input-block">
                    <input name="endTime" id="endTime" type="text" autocomplete="off" required lay-verify="required"
                        class="layui-input">
                </div>
                <label class="layui-form-label">容纳人数:</label>
                <div class="layui-input-block">
                    <input name="maxNum" id="maxNum" type="text" autocomplete="off" required lay-verify="required"
                        class="layui-input">
                </div>
                <label class="layui-form-label">批次描述:</label>
                <div class="layui-input-block">
                    <input name="trainingDescription" id="trainingDescription" type="text" autocomplete="off" required
                        lay-verify="required" class="layui-input">
                </div>
                <label class="layui-form-label">批次类型:</label>
                <div class="layui-input-block">
                    <select name="type" id="type">
                        <option value="">请选择批次类型</option>
                        <option value="0">正在培训</option>
                        <option value="-1">未开始培训</option>
                    </select>
                </div>

            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="float:right;padding-right: 20px">
                    <button class="layui-btn" lay-submit lay-filter="formAdd">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <script type="text/javascript" src="../../static/lib/layui/layui.js" charset="utf-8"
        th:src="@{/lib/layui/layui.js}"></script>
    <script type="text/javascript" src="../../static/js/xadmin.js" th:src="@{/js/xadmin.js}"></script>
    <script type="text/javascript" src="../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
    <!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
    <script th:inline="NONE">
        $('#form-container').css('height', $(window).height() + 'px');
        layui.use(['form', 'table', 'laydate'], function () {
            var form = layui.form;
            var laydate = layui.laydate;
            form.render();
            laydate.render({
                elem: '#startTime',
                type:"datetime"
            })
            laydate.render({
                elem: '#endTime',
                type:"datetime"
            })

            form.on('submit(formAdd)', function (data) {
                console.log(JSON.stringify(data.field));
                var data = data.field;
                var newData = data;
                newData.type =  JSON.parse(data.type);
                $.ajax({
                    url: '/v1/training/addTrainingBatch',
                    contentType: 'application/json',
                    type: 'POST',
                    data: JSON.stringify(newData),
                    success: function (res) {
                        console.log("成功了");
                        layer.msg(res.msg);
                    }, error: function (res) {
                        console.log("失败", res.msg);
                    }, complete: function (res) {
                        console.log("完成", res);
                    }
                })
            })
        });
    </script>
</body>

</html>